home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Tool Chest / Development Kits / MPW etc. / Debuggers / Power Mac Debugger / Debugger Extensions / Sample_ndcd / Echo.c next >
Encoding:
C/C++ Source or Header  |  1997-01-30  |  1.4 KB  |  76 lines  |  [TEXT/MPS ]

  1. /*
  2.  
  3.     File:        Echo.c
  4.  
  5.     Contains:    Sample debugger extension
  6.  
  7. */
  8.  
  9.  
  10. #include <Types.h>
  11. #include <string.h>
  12. #include "dcmd.h"
  13.  
  14. /* Prototypes */
  15. void NumberToHex (long number, unsigned char *hex);
  16. pascal void CommandEntry (dcmdBlock* paramPtr);
  17.  
  18. /* The functions */
  19. void NumberToHex (long number, unsigned char *hex)
  20. {
  21.     unsigned char digits[17];
  22.     int        n;
  23.  
  24.     strcpy ((char *)hex, ".00000000");
  25.     strcpy ((char *)digits, "0123456789ABCDEF");
  26.  
  27.     hex[0] = 8;
  28.     for (n = 8; n >= 1; n--)
  29.         {
  30.         hex[n] = digits[number % 16];
  31.         number = number / 16;
  32.         }
  33. } // NumberToHex
  34.  
  35.  
  36. pascal void CommandEntry (dcmdBlock* paramPtr)
  37. {
  38.     short    pos, ch;
  39.     long    value;
  40.     Boolean    ok;
  41.     unsigned char str[256];
  42.  
  43.     switch (paramPtr->request)
  44.         {
  45.         case dcmdInit:
  46.             break;
  47.  
  48.         case dcmdHelp:
  49.             strcpy((char *)str, (char *)"\p ECHO [params...]");
  50.             dcmdDrawLine (str);
  51.             strcpy((char *)str, (char *)"\p   Echo the command line parameters");
  52.             dcmdDrawLine (str);
  53.             break;
  54.  
  55.         case dcmdDoIt:
  56.             do {
  57.                 // Save the position so we can rewind if we get an error
  58.                 pos = dcmdGetPosition ();
  59.                 ch = dcmdGetNextExpression (&value, &ok);
  60.                 if (ok)
  61.                     { // The expression was parsed correctly
  62.                     NumberToHex (value, str);
  63.                     dcmdDrawLine (str);
  64.                     }
  65.                 else
  66.                     { // The expression contained an error. Get it as a string
  67.                     dcmdSetPosition (pos);
  68.                     ch = dcmdGetNextParameter (str);
  69.                     dcmdDrawLine (str);
  70.                     }
  71.             } while (ch != '\n' && ch != '\r');
  72.             break;
  73.         }
  74. } // CommandEntry
  75.  
  76.